package expressions.slogo;

import parsing.Token;
import expressions.IContext;
import expressions.Prefix;

/**
 * Repeatedly evaluates a command some number of times.
 */
@Token(regex = "repeat")
public class Repeat extends Prefix<Double>
{
    public Repeat()
    {
        super(2);
    }

    @Override
    public Double evaluate(IContext<Double> context)
    {
        int count = (int) (double) children.get(0).evaluate(context);
        double result = 0;

        for (int i = 0; i < count; i++)
        {
            result = children.get(1).evaluate(context);
        }

        return result;
    }

}
